/**
 * 函数sleep，参数单位 毫秒
 */
export const wait = (ms) => {
  return new Promise((resolve) => setTimeout(() => resolve(), ms))
}

/**
 * 判断浏览器函数
 */
export const isMobile = () => {
  if (
    window.navigator.userAgent.match(
      /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
    )
  ) {
    return true // 移动端
  } else {
    return false // PC端
  }
}

/**
 * 随机生成数字+字母
 * @param {Number} num
 * @returns
 */
export const randomString = (num) => {
  let str = ''
  let randomchar = function () {
    let n = Math.floor(Math.random() * 20)
    if (n < 10) return n //1-10
    // if (n < 20) String.fromCharCode(Math.round(Math.random() * 25) + 65) //A-Z
    return String.fromCharCode(Math.round(Math.random() * 25) + 97) //a-z
  }
  while (str.length < num) str += randomchar()
  return str
}
/**
 * 随机生成数字
 * @param {Number} num
 * @returns
 */
export const randomNumber = (num) => {
  let str = ''
  while (str.length < num) str += Math.floor(Math.random() * 10)

  return str
}
